package com.sec.samsung.android.app.baymax.view.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RelativeLayout;

import com.sec.samsung.android.app.baymax.R;
import com.sec.samsung.android.app.baymax.model.Symptom;

public class ListSymptomAdapter extends BaseAdapter {

    private Context mContext;
    private ArrayList<Symptom> mListDataSymptoms;
    private OnCheckItemListener listener;

    public ListSymptomAdapter(Context context, ArrayList<Symptom> listDataSymptoms) {
        this.mContext = context;
        this.mListDataSymptoms = listDataSymptoms;
    }

    public void addSymptom(Symptom symptom) {
        mListDataSymptoms.add(symptom);
        notifyDataSetChanged();
    }

    public void addSymptoms(ArrayList<Symptom> listSymptoms) {
        mListDataSymptoms = listSymptoms;
        notifyDataSetChanged();
    }

    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        if (convertView == null) {
            convertView = (RelativeLayout) RelativeLayout.inflate(mContext, R.layout.symptom_item, null);
        }

        CheckBox checkBox = (CheckBox) convertView.findViewById(R.id.checkbox_suggestion_symptoms);
        checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                listener.onCheckItemLisntener(position, isChecked);
            }
        });
        checkBox.setText(mListDataSymptoms.get(position).getSymptom());

        return convertView;
    }

    @Override
    public int getCount() {
        return mListDataSymptoms.size();
    }

    @Override
    public Symptom getItem(int position) {
        return mListDataSymptoms.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public boolean containsSymptom(Symptom symptom) {
        if (mListDataSymptoms.contains(symptom))
            return true;
        return false;
    }

    public interface OnCheckItemListener {
        public void onCheckItemLisntener(int position, boolean value);
    }

    public void setLisntener(OnCheckItemListener listener) {
        this.listener = listener;
    }
}